﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.UI;

namespace Terraria.ModLoader.UI
{
	// Token: 0x0200027F RID: 639
	public class UICycleImage : UIElement
	{
		// Token: 0x14000032 RID: 50
		// (add) Token: 0x06001A1C RID: 6684 RVA: 0x00427DAC File Offset: 0x00425FAC
		// (remove) Token: 0x06001A1D RID: 6685 RVA: 0x00427DE4 File Offset: 0x00425FE4
		public event EventHandler OnStateChanged;

		// Token: 0x170001C3 RID: 451
		// (get) Token: 0x06001A1E RID: 6686 RVA: 0x0001288C File Offset: 0x00010A8C
		// (set) Token: 0x06001A1F RID: 6687 RVA: 0x00012894 File Offset: 0x00010A94
		public int CurrentState
		{
			get
			{
				return this.currentState;
			}
			set
			{
				if (value != this.currentState)
				{
					this.currentState = value;
					EventHandler onStateChanged = this.OnStateChanged;
					if (onStateChanged == null)
					{
						return;
					}
					onStateChanged(this, EventArgs.Empty);
				}
			}
		}

		// Token: 0x06001A20 RID: 6688 RVA: 0x00427E1C File Offset: 0x0042601C
		public UICycleImage(Texture2D texture, int states, int width, int height, int textureOffsetX, int textureOffsetY, int padding = 2)
		{
			this.texture = texture;
			this._drawWidth = width;
			this._drawHeight = height;
			this.textureOffsetX = textureOffsetX;
			this.textureOffsetY = textureOffsetY;
			this.Width.Set((float)width, 0f);
			this.Height.Set((float)height, 0f);
			this.states = states;
			this.padding = padding;
		}

		// Token: 0x06001A21 RID: 6689 RVA: 0x00427E8C File Offset: 0x0042608C
		protected override void DrawSelf(SpriteBatch spriteBatch)
		{
			CalculatedStyle dimensions = base.GetDimensions();
			Point point = new Point(this.textureOffsetX, this.textureOffsetY + (this.padding + this._drawHeight) * this.currentState);
			Color color = base.IsMouseHovering ? Color.White : Color.Silver;
			spriteBatch.Draw(this.texture, new Rectangle((int)dimensions.X, (int)dimensions.Y, this._drawWidth, this._drawHeight), new Rectangle?(new Rectangle(point.X, point.Y, this._drawWidth, this._drawHeight)), color);
		}

		// Token: 0x06001A22 RID: 6690 RVA: 0x000128BC File Offset: 0x00010ABC
		public override void Click(UIMouseEvent evt)
		{
			this.CurrentState = (this.currentState + 1) % this.states;
			base.Click(evt);
		}

		// Token: 0x06001A23 RID: 6691 RVA: 0x000128DA File Offset: 0x00010ADA
		public override void RightClick(UIMouseEvent evt)
		{
			this.CurrentState = (this.currentState + this.states - 1) % this.states;
			base.RightClick(evt);
		}

		// Token: 0x06001A24 RID: 6692 RVA: 0x000128FF File Offset: 0x00010AFF
		internal void setCurrentState(int sortMode)
		{
			this.CurrentState = sortMode;
		}

		// Token: 0x04001769 RID: 5993
		private Texture2D texture;

		// Token: 0x0400176A RID: 5994
		private int _drawWidth;

		// Token: 0x0400176B RID: 5995
		private int _drawHeight;

		// Token: 0x0400176C RID: 5996
		private int padding;

		// Token: 0x0400176D RID: 5997
		private int textureOffsetX;

		// Token: 0x0400176E RID: 5998
		private int textureOffsetY;

		// Token: 0x0400176F RID: 5999
		private int states;

		// Token: 0x04001771 RID: 6001
		private int currentState;
	}
}
